<template>
  <div>
    <div class="form">
      <div class="search">
        <el-input placeholder="客户名称" v-model="customerName" class="search_info">
          <i slot="prefix" class="el-input__icon el-icon-search"></i>
        </el-input>
        <el-input placeholder="产品名称" v-model="productName" class="search_info">
          <i slot="prefix" class="el-input__icon el-icon-search"></i>
        </el-input>
        <div class="pos_right_btn">
          <el-button class="searchBtn" @click="reset()">重置</el-button>
          <el-button type="primary" @click="getList(1)" class="searchBtn">搜索</el-button>
        </div>
      </div>
      <el-table
        class="listTable"
        ref="multipleTable"
        v-loading="listLoading"
        :data="list"
        border
        fit
        highlight-current-row
        style="width: 100%;"
        @selection-change="handleSelectionChange"
      >
        <!-- <el-table-column type="selection" >
          
        </el-table-column>-->
        <el-table-column label="业务流水号" prop="id" width="100" align="center">
          <template slot-scope="{row}">
            <span>{{ row.renewLoanId }}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户名称" align="center">
          <template slot-scope="{row}">
            <span>{{ row.customerName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="区域" align="center">
          <template slot-scope="{row}">
            <span>{{ row.customerArea }}</span>
          </template>
        </el-table-column>
        <el-table-column label="贷款产品名称" width="160" align="center">
          <template slot-scope="{row}">
            <span>{{ row.productName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="预授信额度" align="center">
          <template slot-scope="{row}">
            <span>{{ row.approveAmount }}</span>
          </template>
        </el-table-column>
        <el-table-column label="预授信机构" align="center">
          <template slot-scope="{row}">
            <span>{{ row.financeName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="管户机构" width="100" align="center">
          <template slot-scope="{row}">
            <span>{{ row.createDept }}</span>
          </template>
        </el-table-column>
        <el-table-column label="管户人" align="center">
          <template slot-scope="{row}">
            <span>{{ row.createName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="状态" align="center">
          <template slot-scope="{row}">
            <span>{{ row.statu }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="160" align="center">
          <template slot-scope="{row}">
            <div class="opt_table">
              <div
                class="opt_font"
                @click="preview(row.reqId, row.customerId, row.flowUid, row.warrantId, row.status)"
                v-if="row.status != '1010' && row.status != '10'"
              >详情</div>
              <div
                class="opt_font"
                v-if="row.status == '1010' || row.status == '10'"
                @click="preview(row.reqId, row.customerId, row.flowUid, row.warrantId, row.status)"
              >审核</div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="footer">
        <div class="footer_btn"></div>
        <el-pagination
          :total="total"
          layout="total, sizes, prev, pager, next"
          :page-size="limit"
          :page-sizes="[10, 20, 50, 100]"
          @size-change="handleSizeChange"
          :current-page.sync="curPage"
          @current-change="getList($event)"
          class="sortStyle"
        />
      </div>
      <el-dialog :visible.sync="detailShow" :title="infoTitle" width="1096px">
        <div>
          <div class="detail_title pos_top">
            <div class="apply">
              <div>
                <span></span>
                担保申请
              </div>
              <!-- <div class="apply_btn">
                <el-button type="primary">发起担保</el-button>
              </div>-->
              <div class="apply_btn" v-if="statusChange">
                <el-button type="primary" @click="checkReset()">审核</el-button>
              </div>
            </div>
          </div>
          <el-table
            class="detailTable"
            v-loading="listLoading"
            :data="provinceList"
            border
            fit
            highlight-current-row
            style="width: 100%;"
          >
            <el-table-column label="序号" align="center" type="index"></el-table-column>
            <el-table-column label="业务流水号" align="center">
              <template slot-scope="{row}">
                <span>{{ row.bizWarrantInfo.applyId }}</span>
              </template>
            </el-table-column>
            <el-table-column label="申请时间" align="center">
              <template slot-scope="{row}">
                <span>{{ row.bizWarrantInfo.publishDate }}</span>
              </template>
            </el-table-column>
            <el-table-column label="担保机构" align="center">
              <template slot-scope="{row}">
                <span>{{ row.warrantDeptName }}</span>
              </template>
            </el-table-column>
            <el-table-column label="业务进度" align="center">
              <template slot-scope="{row}">
                <span v-if="row.bizWarrantInfo.status == '1010'">处理中</span>
                <span v-if="row.bizWarrantInfo.status == '2000'">已通过</span>
                <span v-if="row.bizWarrantInfo.status == '3000'">已拒绝</span>
              </template>
            </el-table-column>
            <el-table-column label="担保额度" align="center">
              <template slot-scope="{row}">
                <span>{{ row.bizWarrantInfo.guaranteeAmount }}</span>
              </template>
            </el-table-column>
            <el-table-column label="担保期限" align="center">
              <template slot-scope="{row}">
                <span>{{ row.bizWarrantInfo.guaranteeTime }}</span>
              </template>
            </el-table-column>
            <el-table-column label="担保利率" align="center">
              <template slot-scope="{row}">
                <span>{{ row.bizWarrantInfo.guaranteeRadio }}</span>
              </template>
            </el-table-column>
          </el-table>
          <div class="detail_title pos_top">
            <span></span>
            需求信息
          </div>
          <el-table
            class="detailTable"
            v-loading="listLoading"
            :data="needData"
            border
            fit
            highlight-current-row
            style="width: 100%;"
          >
            <el-table-column label="需求编号" prop="id" align="center">
              <template slot-scope="{row}">
                <span>{{ row.reqId }}</span>
              </template>
            </el-table-column>
            <el-table-column label="企业名称" align="center">
              <template slot-scope="{row}">
                <span>{{ row.customerName }}</span>
              </template>
            </el-table-column>
            <el-table-column label="申请产品" align="center">
              <template slot-scope="{row}">
                <span>{{ row.productName }}</span>
              </template>
            </el-table-column>
            <el-table-column label="担保方式" align="center">
              <template slot-scope="{row}">
                <span v-if="row.guaranteeType == '' || row.guaranteeType == 9">不限</span>
                <span v-if="row.guaranteeType === '0'">抵押</span>
                <span v-if="row.guaranteeType == 1">质押</span>
                <span v-if="row.guaranteeType == 2">信用</span>
                <span v-if="row.guaranteeType == 3">一般保证</span>
              </template>
            </el-table-column>
            <el-table-column label="融资金额(万元)" align="center">
              <template slot-scope="{row}">
                <span>{{ row.financeAmount }}</span>
              </template>
            </el-table-column>
            <el-table-column label="融资期限" align="center">
              <template slot-scope="{row}">
                <span>{{ row.financeTime }}</span>
              </template>
            </el-table-column>
          </el-table>
          <div class="detail_title pos_top top_more">
            <span></span>
            企业基本信息
          </div>
          <div class="detail_info">
            <div class="row">
              <div class="info_left">
                <div class="info_left_title">
                  <div class="font">企业名称</div>
                </div>
                <div class="info_left_content">{{listData.name}}</div>
              </div>
              <div class="info_right">
                <div class="info_left_title">
                  <div class="font">统一社会信用代码</div>
                </div>
                <div class="info_left_content">{{listData.uniscId}}</div>
              </div>
            </div>
            <div class="row">
              <div class="info_left">
                <div class="info_left_title">
                  <div class="font">企业类型</div>
                </div>
                <div class="info_left_content">{{listData.econat}}</div>
              </div>
              <div class="info_right">
                <div class="info_left_title">
                  <div class="font">经营状态</div>
                </div>
                <div class="info_left_content">{{listData.entState}}</div>
              </div>
            </div>
            <div class="row">
              <div class="info_left">
                <div class="info_left_title">
                  <div class="font">所属行业</div>
                </div>
                <div class="info_left_content">{{listData.industry}}</div>
              </div>
              <div class="info_right">
                <div class="info_left_title">
                  <div class="font">成立时间</div>
                </div>
                <div class="info_left_content">{{parseTime(listData.estDate,'{y}-{m}-{d}')}}</div>
              </div>
            </div>
            <div class="row">
              <div class="info_left">
                <div class="info_left_title">
                  <div class="font">公司类型</div>
                </div>
                <div class="info_left_content">{{listData.entTypeName}}</div>
              </div>
              <div class="info_right">
                <div class="info_left_title">
                  <div class="font">法定代表人</div>
                </div>
                <div class="info_left_content">{{listData.legalPerson}}</div>
              </div>
            </div>
            <div class="row">
              <div class="info_left">
                <div class="info_left_title">
                  <div class="font">发照日期</div>
                </div>
                <div class="info_left_content">{{parseTime(listData.apprDate,'{y}-{m}-{d}')}}</div>
              </div>
              <div class="info_right">
                <div class="info_left_title">
                  <div class="font">企业地址</div>
                </div>
                <div class="info_left_content">{{listData.address}}</div>
              </div>
            </div>
            <div class="row">
              <div class="info_left">
                <div class="info_left_title">
                  <div class="font">注册资本(万元)</div>
                </div>
                <div class="info_left_content">{{listData.regcap}}</div>
              </div>
              <div class="info_right">
                <div class="info_left_title">
                  <div class="font">行政区划</div>
                </div>
                <div class="info_left_content">{{listData.branchNo}}</div>
              </div>
            </div>
            <div class="row">
              <div class="info_left">
                <div class="info_left_title" style="height:unset">
                  <div class="font">经营范围</div>
                </div>
                <div class="info_left_contents">{{listData.opScope}}</div>
              </div>
            </div>
          </div>
          <div class="detail_title pos_top">
            <span></span>
            抵质押物信息
          </div>
          <el-table
            class="detailTable"
            :data="goodsList"
            border
            fit
            highlight-current-row
            style="width: 100%;"
          >
            <el-table-column label="序号" type="index" align="center">
              <!-- <template slot-scope="{row}">
                <span>{{ row.bizApplyGuaranteePledgeRelativeList }}</span>
              </template>-->
            </el-table-column>
            <el-table-column label="抵质押物类型" align="center">
              <template slot-scope="{row}">
                <span v-if="row.relativeType == '03'">抵押物</span>
                <span v-if="row.relativeType == '02'">质押物</span>
                <span v-if="row.relativeType == '04'">担保合同</span>
                <span v-if="row.relativeType == '01'">房产</span>
              </template>
            </el-table-column>
            <el-table-column label="预估价值" align="center">
              <template slot-scope="{row}">
                <span>{{ row.estimatedAmount }}</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- <div class="backBtn">
          <el-button @click="goback">返回</el-button>
          <el-button type="primary" @click="sendShow = true">分发</el-button>
        </div>-->
      </el-dialog>
      <div class="check">
        <el-dialog :visible.sync="checkShow" title="担保审批信息" width="666px">
          <div class="centers">
            <div>
              <div class="flex_row pad_top">
                <div class="font_info">保证合同编号</div>
                <el-input v-model="guaranteeNo" placeholder="请输入保证合同编号" class="input_info" />
              </div>
              <div class="flex_row pad_top">
                <div class="font_info">担保授信金额</div>
                <el-input v-model="guaranteeAmount" placeholder="请输入担保授信金额（万元）" class="input_info" />
              </div>
              <div class="flex_row pad_top">
                <div class="font_info">担保费率</div>
                <el-input v-model="guaranteeRadio" placeholder="请输入担保费率（%）" class="input_info" />
              </div>
              <div class="flex_row pad_top">
                <div class="font_info">担保期限</div>
                <el-input v-model="guaranteeTime" placeholder="请输入担保期限（个月）" class="input_info" />
              </div>
              <div class="footers">
                <el-button @click="close()">返回</el-button>
                <el-button type="primary" class="searchBtn" @click="sure()">确定</el-button>
              </div>
            </div>
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>

<script>
import {
  auditing,
  bizRenewLoanInfoList,
  getBizApplyInfo,
  getRecordList
} from "@/api/system/user";
import { MessageBox } from "element-ui";
export default {
  components: {},
  data() {
    return {
      data: [
        {
          id: 1,
          label: "一级 1",
          children: [
            {
              id: 4,
              label: "二级 1-1",
              children: [
                {
                  id: 9,
                  label: "三级 1-1-1"
                },
                {
                  id: 10,
                  label: "三级 1-1-2"
                }
              ]
            }
          ]
        },
        {
          id: 2,
          label: "一级 2",
          children: [
            {
              id: 5,
              label: "二级 2-1"
            },
            {
              id: 6,
              label: "二级 2-2"
            }
          ]
        },
        {
          id: 3,
          label: "一级 3",
          children: [
            {
              id: 7,
              label: "二级 3-1"
            },
            {
              id: 8,
              label: "二级 3-2"
            }
          ]
        }
      ],
      workCode: "",
      workStatus: "",
      status: [],
      list: [],
      listLoading: false,
      total: 0,
      limit: 10,
      curPage: 1,
      listData: [],
      detailShow: false,
      value: "",
      needData: [],
      loanList: [],
      moneyList: [],
      sendShow: false,
      props: {
        label: "name",
        children: "zone"
      },
      count: 1,
      customerName: "",
      productName: "",
      reqId: "",
      flowUid: "",
      infoTitle: "",
      checkShow: false,
      warrantId: "",
      guaranteeNo: "",
      guaranteeAmount: "",
      guaranteeTime: "",
      guaranteeRadio: "",
      goodsList: [],
      provinceList: [],
      statusChange: false,
      customerId: ""
    };
  },
  created() {},
  mounted() {
    this.getList(1);
  },
  methods: {
    checkReset() {
      this.guaranteeNo = "";
      this.guaranteeAmount = "";
      this.guaranteeTime = "";
      this.guaranteeRadio = "";
      this.checkShow = true;
    },
    sure() {
      var params = {
        status: "2000",
        bizId: this.reqId,
        flowUid: this.flowUid,
        warrantId: this.warrantId,
        guaranteeNo: this.guaranteeNo,
        guaranteeAmount: this.guaranteeAmount,
        guaranteeTime: this.guaranteeTime,
        guaranteeRadio: this.guaranteeRadio
      };
      auditing(params).then(res => {
        if (res.code == 200) {
          this.$message({ message: res.msg, type: "success" });
        } else {
          this.$message({ message: res.msg, type: "error" });
        }
        this.checkShow = false;
        this.getList(1);
        this.preview(
          this.reqId,
          this.customerId,
          this.flowUid,
          this.warrantId,
          this.status
        );
      });
    },
    //审核关闭
    close() {
      this.checkShow = false;
    },
    reset() {
      this.customerName = "";
      this.productName = "";
    },
    /** 查询用户列表 */
    getList(page) {
      var params = {
        pageNum: page,
        pageSize: this.limit,
        customerName: this.customerName,
        productName: this.productName
      };
      this.listLoading = true;
      bizRenewLoanInfoList(params).then(response => {
        this.list = response.rows;
        this.list.forEach(element => {
          if (element.status == "1010" || element.status == "10") {
            element.statu = "办理中";
          } else if (element.status == "2000") {
            element.statu = "已担保";
          } else {
            element.statu = "已拒绝";
          }
        });
        this.total = response.total;
        this.listLoading = false;
      });
    },
    handleCheckChange(data, checked, indeterminate) {
      console.log(data, checked, indeterminate);
    },
    handleNodeClick(data) {
      console.log(data);
    },
    loadNode(node, resolve) {
      debugger;
      if (node.level === 0) {
        return resolve([{ name: "region1" }, { name: "region2" }]);
      }
      if (node.level > 3) return resolve([]);
      var hasChild;
      if (node.data.name === "region1") {
        hasChild = true;
      } else if (node.data.name === "region2") {
        hasChild = false;
      } else {
        hasChild = Math.random() > 0.5;
      }
      setTimeout(() => {
        var data;
        if (hasChild) {
          data = [
            {
              name: "zone" + this.count++
            },
            {
              name: "zone" + this.count++
            }
          ];
        } else {
          data = [];
        }
      });
    },
    //多选
    handleSelectionChange(rows) {
      console.log(rows);
    },
    goback() {
      this.detailShow = false;
    },
    handleSizeChange(val) {
      this.limit = val;
      this.getList(1);
    },
    //任务详情
    preview(id, cid, fid, wid, status) {
      this.warrantId = wid;
      this.reqId = id;
      this.flowUid = fid;
      this.customerId = cid;
      this.needData = [];
      this.detailShow = true;
      if (status == "1010") {
        this.statusChange = true;
      } else {
        this.statusChange = false;
      }
      var params = {
        reqId: id
        // customerId: cid,
      };
      getBizApplyInfo(params).then(response => {
        this.infoTitle = response.customerName;
        this.needData.push(response);
        if (response.fspCorInf) {
          this.listData = response.fspCorInf;
        }
        if (response.bizApplyGuaranteePledgeRelativeList) {
          this.goodsList = response.bizApplyGuaranteePledgeRelativeList;
        }
        if (response.bizApplyWarrantRelativeList) {
          this.provinceList = response.bizApplyWarrantRelativeList;
        }
      });
    }
  }
};
</script>
<style scoped>
.form {
  padding-left: 26px;
  padding-right: 24px;
  padding-top: 24px;
  background: #fff;
}
.search {
  display: flex;
  position: relative;
}
.search_info {
  width: 180px;
  height: 40px;
  margin-right: 16px;
}
.searchBtn {
  margin-left: 16px;
  height: 36px;
}
.sortStyle {
  height: 19px;
  float: right;
  /* right: 24px; */
  margin-top: 20px;
  margin-bottom: 30px;
}
.pos_right_btn {
  position: absolute;
  right: 0;
}
.opt_font {
  cursor: pointer;
  color: #2e82ff;
}
.detail_title {
  font-size: 16px;
  font-weight: 400;
  color: #212121;
  line-height: 22px;
}
.detail_title span {
  padding-left: 4px;
  background: #1e88e5;
  margin-right: 12px;
}
.row {
  display: flex;
  /* padding-bottom: 12px; */
}
.detail_info {
  padding-top: 16px;
}
.info_left {
  display: flex;
}
.info_right {
  display: flex;
  /* padding-left: 202px; */
}
.info_left_title {
  font-size: 14px;
  font-weight: 400;
  color: #616161;
  line-height: 20px;
  width: 256px;
  /* margin-right: 16px; */
  text-align: center;
  min-height: 47px;
  background: #f5f7fa;
  box-shadow: inset 0 -1px 0 0 #dcdfe6;
}
.info_left_title .font {
  position: relative;
  top: 14px;
}
.info_left_content {
  font-size: 14px;
  font-weight: 400;
  color: #212121;
  line-height: 20px;
  width: 256px;
  /* border: 1px solid #DCDFE6; */
  box-shadow: inset -1px -1px 0 0 #dcdfe6;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}
.info_left_contents {
  font-size: 14px;
  font-weight: 400;
  color: #212121;
  line-height: 20px;
  width: 769px;
  /* border: 1px solid #DCDFE6; */
  box-shadow: inset -1px -1px 0 0 #dcdfe6;
  text-align: left;
}
.pos_top {
  padding-top: 12px;
}
.top_more {
  margin-top: 8px;
}
.detailTable {
  margin-top: 16px;
}
.opt_font {
  color: #1e88e5;
  cursor: pointer;
}
.page_pos {
  text-align: right;
  padding-top: 10px;
}
.backBtn {
  text-align: center;
  margin-top: 10px;
}
/deep/ .el-dialog {
  display: flex;
  flex-direction: column;
  margin: 0 !important;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-height: calc(100% -30px);
  /* max-width: ; */
}
/deep/ .el-dialog .el-dialog__body {
  flex: 1;
  height: 600px;
  overflow-y: auto;
  padding-top: 0;
}
.tab {
  display: flex;
  position: absolute;
  right: 32px;
  top: 14px;
}
.tab_border {
  border: 1px solid #409eff;
  color: #409eff;
  padding: 10px 12px;
  font-size: 14px;
  margin-right: 16px;
}
.change {
  border: 1px solid #f56c6c;
  color: #f56c6c;
}
.listTable {
  margin-top: 17px;
}
/deep/ .search_info .el-input__inner {
  width: 180px;
}
.date_picker /deep/ .el-input__inner {
  width: 240px;
}
.opt_table {
  display: flex;
  justify-content: space-around;
}
.footer {
  display: flex;
  justify-content: space-between;
}
.footer_btn {
  position: relative;
  top: 20px;
}
.upload {
  /* background:  */
}
.apply {
  display: flex;
  position: relative;
}
.apply_btn {
  position: absolute;
  right: 0px;
  top: -8px;
}
.flex_row {
  display: flex;
  /* justify-content: center; */
}
.pad_top {
  padding-bottom: 16px;
}
.centers {
  display: flex;
  justify-content: center;
  width: 100%;
  text-align: center;
}
.font_info {
  width: 100px;
  text-align: right;
  position: relative;
  top: 8px;
}
.input_info {
  width: 300px;
}
</style>
